<?php

namespace app\admin\model\store;

use think\Model;


class Serve extends Model
{

    

    

    // 表名
    protected $name = 'serve';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'serve_type_text',
        'is_added_text',
        'serve_status_text',
        'is_recommend_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getServeTypeList()
    {
        return ['0' => __('Serve_type 0'), '1' => __('Serve_type 1')];
    }

  public function getServeStatusList()
  {
    return ['1' => __('审核通过'), '2' => __('审核失败'), '3' => __('审核中')];
  }

    public function getIsAddedList()
    {
        return ['0' => __('Is_added 0'), '1' => __('Is_added 1')];
    }

    public function getIsRecommendList()
    {
        return ['1' => __('Is_recommend 1'), '2' => __('Is_recommend 2')];
    }


    public function getServeTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['serve_type']) ? $data['serve_type'] : '');
        $list = $this->getServeTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsAddedTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_added']) ? $data['is_added'] : '');
        $list = $this->getIsAddedList();
        return isset($list[$value]) ? $list[$value] : '';
    }

  public function getServeStatusTextAttr($value, $data)
  {
    $value = $value ? $value : (isset($data['serve_status']) ? $data['serve_status'] : '');
    $list = $this->getServeStatusList();
    return isset($list[$value]) ? $list[$value] : '';
  }


    public function getIsRecommendTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_recommend']) ? $data['is_recommend'] : '');
        $list = $this->getIsRecommendList();
        return isset($list[$value]) ? $list[$value] : '';
    }


  public function servelabel()
  {
    return $this->belongsTo('app\admin\model\store\Servelabel', 'label', 'id', [], 'LEFT')->setEagerlyType(0);
  }

  public function servec()
  {
    return $this->belongsTo('app\admin\model\store\Servec', 'serve_cid', 'id', [], 'LEFT')->setEagerlyType(0);
  }

  public function store()
  {
    return $this->belongsTo('app\admin\model\store\Store', 'store_id', 'store_id', [], 'LEFT')->setEagerlyType(0);
  }

}
